adding TYPE_API, and API remediation to perform config_merge operatio…#1066
adding TYPE_API, and API remediation to perform config_merge operatio…#1066huacchob wants to merge 2 commits intonautobot:developfrom
Conversation
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||
| key: Any | ||
|
|
||
|
|
||
| class ApiRemediation: # pylint: disable=too-few-public-methods |
There was a problem hiding this comment.
Can you explain this a bit more? Ideally, this logic is coming from some other library vs some custom logic.
There was a problem hiding this comment.
The remediation will travel down the path of the API response. The different data types we find in an API response are lists, dictionaries, and scalars (strings, integers, floats, booleans). The difference between scalars and dictionaries is being handled, because the code checks the type of the data, and continue traversing the path accordingly:
- If the current type is a dictionary or a list, the remediation engine will continue to travel the path.
- If the current value is an integer, float, boolean, or string, it will know to end traveling the path there.
The problem we are trying to fix here is what happens when the dictionary key is an integer? Without DictKeys we would have a path that consists of dict keys (which are scalars), list indexes (which are integers), and final scalars (the end of a path). When we rebuild the path in the _process_diff method, and we come across an integer, the _process_diff method will not know if the integer is a list index or a dictionary key. This is why we would need the DictKey class.
There was a problem hiding this comment.
But what other options were considered? Like did we look at how we could potentially use jdiff or Dictdiffer?
There was a problem hiding this comment.
Okay, I understand. I haven't used Dictdiffer or explored too many other options. I have attempted to use jdiff. The error I came across two errors, one I have a PR for 144 and another issue with how lists are flattened.
I will go ahead and do some research on what other tools I could use, starting with Dictdiffer
There was a problem hiding this comment.
I have added deepdiff as the diff engine here. While there is more code to make the code work with deepdiff, because of some custom logic (such as removal of unwanted fields in the response), I do think this provides more flexibility in how you would like to handle remediation, because deepdiff shows diff scenarios, such as index item removed/added, dictionary key added/removed, dict value removed/added and so on.
…ns for API based devices, such as Meraki, associated tests and documentation
330b16a to
cad4d2e
Compare
Closes: #1064
What's Changed
Adding TYPE_API option for remediation and the API JSON remediation engine. I also added the updated documentation and tests
To Do